<?php 
/**
 * 个人中心控制器
 */
class MemberController extends Controller{
	
	public function index(){
		if(IS_POST){
    		//实例化扩展UserModel模型
    		$model = K('VipUser');
			$_POST['birthday'] = $_POST['YYYY'].'/'.$_POST['MM'];
			if(!$model->addData()){
				$this->error($model->error);
			}
			$this->success('填写成功');
    	}
		$uid = $_SESSION['uid'];
		//个人资料
		$userInfo = K('User')->where("uid={$uid}")->find();
		$this->assign('userInfo',$userInfo);
		//个人地址信息
		$address = K('Address')->where("user_uid={$uid}")->all();
		$this->assign('address',$address);
	    $this->display();
	}
	
	
	
	
	
    /**
     * 验证码
     */
    public function code(){
       $code = new Code();
	   $code->show();
    }
	
	
	/**
	 * 异步检测用户名是否存在--注册
	 */
	public function check_REG_User(){
	    if(!IS_AJAX) return;
		$username = Q('post.username');
		$data=K('User')->where("username='{$username}'")->find();
		if($data){
			echo json_encode(array('status'=>false,'message'=>'用户名已存在'));
		}else{
			echo json_encode(array('status'=>true,'message'=>'用户名可以注册'));
		}
		exit;
	}
	
	
	/**
	 * 异步检测用户名是否存在--登录
	 */
	public function check_LOG_User(){
	    if(!IS_AJAX) return;
		$username = Q('post.username');
		$data=K('User')->where("username='{$username}' OR nickname='{$username}'")->find();
		if($data){
			echo json_encode(array('status'=>true,'message'=>'正确'));
		}else{
			echo json_encode(array('status'=>false,'message'=>'用户名不存在'));
		}
		exit;
	}
	
	/**
	 * 异步检测验证码
	 */
	 public function checkCode(){
	     if(!IS_AJAX) return;
		 $code = strtoupper(Q('post.code'));
		 if($code == $_SESSION['code']){
		 	echo json_encode(array('status'=>true,'message'=>'验证通过'));
		 }else{
		 	echo json_encode(array('status'=>false,'message'=>'验证码错误'));
		 }
		 exit;
	 }
 }
 
 
 
 
 
 
 
 
 
 
 





 ?>